package frog.lazy.framework.http.serializer;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;
import frog.lazy.framework.core.base.IBaseEnum;

import java.io.IOException;
import java.util.Optional;

public class IBaseEnumSerializer extends JsonSerializer<IBaseEnum> {

    @Override
    public void serialize(IBaseEnum value, JsonGenerator jgen, SerializerProvider provider) throws IOException {
        Optional<IBaseEnum> data = Optional.of(value);
        if (data.isPresent()) {
            jgen.writeObject(data.get().getValue());
        } else {
            jgen.writeString("");
        }
    }
}
